package com.msmall.community.play.dao.hibernate;

import java.util.List;

import com.msmall.base.dao.hibernate.BaseDaoHibernate;
import com.msmall.community.play.dao.PlayDao;
import com.msmall.community.play.model.Play;
import com.msmall.community.play.model.UserPlay;

public class PlayDaoHibernate extends BaseDaoHibernate<Play, Long> implements PlayDao{

	public PlayDaoHibernate(){
		super(Play.class);
	}
	public List<Play> getByUserid(Long userid) throws Exception {
		try{
			String queryString = "select p from Play p, UserPlay u where u.play.playId=p.playId and u.userid=?";
			return super.getHibernateTemplate().find(queryString,userid);
		}catch(Exception e){
			throw e;
		}
	}
	/**
	 * 获得用户和一个PLAY的关系
	 * @param userid
	 * @param playId
	 * @return
	 */
	public UserPlay getUserPlay(Long userid, Long playId){
		String queryString = "from UserPlay u where u.play.playId=? and u.userid=?";
		List list  = super.getHibernateTemplate().find(queryString, new Object[]{playId,userid});
		if(list != null && list.size() > 0)
			return (UserPlay) list.get(0);
		return null;
	}
}
